package com.agy.filemanager.controller;

import com.agy.filemanager.entity.DcManagerInfo;
import com.agy.filemanager.service.DcSystemManagerInfoService;
import com.agy.filemanager.toolClass.Result;
import com.agy.filemanager.toolClass.ResultUtil;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 系统设置-系统管理员维护
 */
@Controller
@RequestMapping("/systemManagerInfo")
public class SystemManagerInfoController {

    @Autowired
    private DcSystemManagerInfoService dcSystemManagerInfoService;

    /**
     * -select
     * @param request
     * @return
     */
    @PostMapping("/selectManagerInfo")
    @ResponseBody
    public Map<String,Object> selectManagerInfo(HttpServletRequest request){
        int pageSize =Integer.parseInt(request.getParameter("pageSize"));
        int pageNum =Integer.parseInt(request.getParameter("pageNum"));
        String account = request.getParameter("account");
        Page list = this.dcSystemManagerInfoService.selectManagerInfo(pageNum,pageSize,account);
        Map<String,Object> map=new HashMap<>();
        map.put("total",list.getTotal());
        map.put("rows",list.getResult());
        return map;
    }

    /**
     * -delete
     * @param id
     * @return
     */
    @PostMapping("/deleteByid")
    @ResponseBody
    public Result deleteByid(@RequestParam("id") String id){
        this.dcSystemManagerInfoService.deleteById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * -update
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody DcManagerInfo entity){
        entity.setUpdated(new Date(System.currentTimeMillis()));
        this.dcSystemManagerInfoService.update(entity);
        return ResultUtil.success("修改成功");
    }
}
